package com.corpgovernment.common.enums;

import com.ctrip.corp.obt.generic.utils.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author wangyujue
 */
public enum TravelEnum {
    /**
     * 因公
     */
    PUB("PUB", "因公出行"),
    /**
     * 因私
     */
    OWN("OWN", "因私出行");

    /**
     * 出行类型，PUB因公、OWN因私
     */
    private String type;
    /**
     * 中文描述
     */
    private String desc;

    TravelEnum(String type, String desc) {
        this.type = type;
        this.desc = desc;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * type转枚举
     * @param type
     * @return
     */
    public static TravelEnum getByType(String type){
        if (StringUtils.isBlank(type)) {
            return null;
        }
        return Arrays.stream(TravelEnum.values()).filter(p -> p.getType().equals(type)).findFirst().orElse(null);
    }

	/**
	 * type转枚举
	 * @param type
	 * @return
	 */
	public static Optional<TravelEnum> getOptionalByType(String type){
		return Arrays.stream(TravelEnum.values()).filter(p -> p.getType().equals(type)).findFirst();
	}
}
